package com.pig4cloud.pigx.robot.ws.collect.gate;


import com.alibaba.fastjson.JSONObject;
import com.pig4cloud.pigx.robot.ws.collect.bitmex.WsManager;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ParseData {


	public static void parse(String msg){
		try{
			JSONObject json = JSONObject.parseObject(msg);
			if(json!= null){
				if(json.get("channel").equals("futures.tickers")){
					//标记价格
					String k_mark = "robot_gate_markprice_" + json.getJSONArray("result").getJSONObject(0).getString("contract").toUpperCase().replace("_","");

					String v_mark =json.getJSONArray("result").getJSONObject(0).getString("mark_price") + "_" +  json.getString("time")+"000";

					WsManager.getInstance().fetchManager.setdata(k_mark,v_mark);



					//最新成交价格
					String k_last = "robot_gate_lastprice_" + json.getJSONArray("result").getJSONObject(0).getString("contract").toUpperCase().replace("_","");

					String v_last =json.getJSONArray("result").getJSONObject(0).getString("last") + "_" +  json.getString("time")+"000";

					WsManager.getInstance().fetchManager.setdata(k_last,v_last);


					//指数价格
					String k_index = "robot_gate_indexprice_" + json.getJSONArray("result").getJSONObject(0).getString("contract").toUpperCase().replace("_","");

					String v_index =json.getJSONArray("result").getJSONObject(0).getString("index_price") + "_" + json.getString("time")+"000";

					WsManager.getInstance().fetchManager.setdata(k_index,v_index);
				}
			}

		}catch (Exception ex){
			log.error("parse gate data error  "+ex.getMessage());
		}
	}

}
